<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* 1.通过margin：atuo 结合flex, auto作用是平分左右边距；适用于块级元素，常用于不确定高度的情况下，。*/

      /* .outer {
        background-color: blue;
        height: 500px;
        width: 500px;
        display: flex;
        justify-content: center;
      }
      .inner {
        background-color: bisque;
        height: 200px;
        width: 200px;
        margin: auto;
      } */

      /* 2.margin: auto 也可以用于垂直居中，前提是子元素有固定的高度，
      并且父容器有固定的高度。在这种情况下，auto 会让上下外边距平分剩余空间，
      从而使元素在父容器内垂直居中。*/
      /* .outer {
        background-color: blue;
        height: 500px;
        width: 500px;
        position: relative;
      }
      .inner {
        background-color: bisque;
        height: 200px;
        width: 200px;
        margin: auto;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
      } */

      /* 3.子绝父相+translate,父容器要有高度*/
      /* .outer {
        background-color: blue;
        height: 500px;
        width: 500px;
        position: relative;
      }
      .inner {
        background-color: bisque;
        height: 200px;
        width: 200px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      } */

      /* 4.grid*/
      /* .outer {
        background-color: blue;
        height: 500px;
        width: 500px;
        display: grid;
        place-items: center; /* 同时垂直和水平居中 */
      /* }
      .inner {
        background-color: bisque;
        height: 200px;
        width: 200px;
      } */

      /* 5.flex*/
      /* .outer {
        background-color: blue;
        height: 500px;
        width: 500px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .inner {
        background-color: bisque;
        height: 200px;
        width: 200px;
      } */
    </style>
  </head>
  <body>
    <div class="outer">
      <div class="inner"></div>
    </div>
  </body>
</html>
